﻿using System;
using System.Collections.Generic;
using System.Linq;
using Common.Dao;
using Common.Model;
using HotTopic.service;
using log4net;

namespace HotTopic.Script
{
    public class MergeScript
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(MergeScript));
        //        public static void Main(string[] args)
        //        {
        //            Run();
        //        }

        public static void Run()
        {
            Log.Info("merge script start");
            
            TopicMergeService topicMergeService = new TopicMergeService();
            var mergeSoftwareTopics = topicMergeService.MergeSoftwareTopics();
            var topics = mergeSoftwareTopics.Values.ToList();
            
            BlockDao.BatchSaveTopics(topics);
            var stocks = new List<Stock>();
            foreach (Topic topic in topics)
            {
                stocks.AddRange(topic.Stocks);
            }

            Log.Info("stocks count = " + stocks.Count);
            Log.Info("topics count = " + topics.Count);
            BlockDao.BatchSaveStocks(stocks);
            Log.Info("merge script end");
        }
    }
}